package com.dlmu.TreeMap;

import java.util.TreeMap;
import java.util.function.BiConsumer;

public class TreeMapDemo1 {
    public static void main(String[] args) {
        String str="abcccabaccaab";
        TreeMap<Character,Integer>tm=new TreeMap<>();
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if(tm.containsKey(c)){
                int count=tm.get(c);
                count++;
                tm.put(c,count);
            }else {
                tm.put(c,1);
            }
        }

        StringBuilder sb=new StringBuilder();
        tm.forEach(new BiConsumer<Character, Integer>() {
            @Override
            public void accept(Character character, Integer integer) {
                sb.append(character).append("(").append(integer).append(")");
            }
        });

        System.out.println(tm);
        System.out.println("----------");
        System.out.println(sb);
    }
}
